import Vue from 'vue'
import Vuex from 'vuex'
import {http1,http2,http3,http4,http5,http6,http7,http8} from '@/assets/utils.js'
import axios from 'axios'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
		homeBook:[],
		searchList:[],
		searchStart:0,
		showSearch:false,
		bookDetail:[],
		bookDirectory:[],
		SwiperColumns:[],
		EssaysData:[],
		homeCategory:[],
		ebookDetail:[],
  },
  mutations: {
	  homeSearch(state) {
	    state.showSearch=!state.showSearch
	  },
  },
  actions: {
	   
	   // 主页书籍
		getHomeBook(state){
			http1().then(res=>{
				state.state.homeBook=res.data
			})
		},
		
		// 搜索款
		getSearch(state){
			http2(
			{
				baseURL:`/douban/j/search?start=0&limit=10&query=`,
			}
			).then(res=>{
				state.state.searchList=res.data
			})
		},
		
		// 搜索框  书本详情
	 	async getBookDetail(state,bookId){
		 await http3(
			{
				baseURL:`/douban/j/column_v2/${bookId}/`,
			}
			).then(res=>{
				state.state.bookDetail=res.data
			})
		},
		
		// 搜索框
		getBookDirectory(state,bookId){
			http4({
				baseURL:`/douban/j/column_v2/${bookId}/chapters?start=0&limit=10&latestFirst=0`,
			}).then(res=>{
				state.state.bookDirectory=res.data
			})
		},
		
		// 连载页面书籍
		getSwiperColumns(state){
			http5().then(res=>{
				state.state.SwiperColumns=res.data
			})
		},
		// 短篇小说 页面
		getEssays(state){
			http6().then(res=>{
				state.state.EssaysData=res.data
			})
		},
		
		// 首页轮播  的更多
		getHomeCategory(state,categoryName){
			http7({
				baseURL:`/douban/j/category/${categoryName}?start=0&limit=10`,
			}).then(res=>{
				state.state.homeCategory=res.data
			})
		},
		
		// home首页的书籍详情
		getEbookDetail(state,ebookId){
			http7({
				baseURL:`/douban/j/ebook/${ebookId}/`,
			}).then(res=>{
				state.state.ebookDetail=res.data
				
				console.log(res.data)
			})
		},
  },
  modules: {
  }
})
